package com.xinqing.test.LetCode;

/**
 * @Author:CHQ
 * @Date:2021/7/21 15:11
 * @Description
 */
public class CompressString {
    public static void main(String args[]){

        System.out.println(test("aabbcc"));

    }
    public static String test(String s){
        StringBuffer sb=new StringBuffer();
        char c=s.charAt(0);
        int count=1;
        for(int i=1;i<s.length();i++){
            if(c==s.charAt(i)){
                count++;
            }else{
                sb.append(c);
                sb.append(count);
                count=1;
                c=s.charAt(i);
            }
        }
        sb.append(c);
        sb.append(count);
        return sb.toString();
    }
}
